<?php
include_once('libs/class.database.php');

class Carosel
{
	public $link;
	
	function __construct()
	{
		$konek= new Database();
		$this->link=$konek->connect();
	}
	
	
	function getCarosel()
	{
		$query=$this->link->query("SELECT * FROM carosel ORDER BY date_created DESC");
		$jml_data=$query->rowCount();
		if($jml_data>=1)
		{
			$hasil=$query->fetchAll();
			return $hasil;
		}
		else
		{
			return $jml_data;
		}
	}
	
	function delCarosel($id)
	{
		$query=$this->link->query("DELETE FROM carosel WHERE id=$id");
		$jml_data=$query->rowCount();
		return $jml_data;
	}
	
	function getExtension($str) {
		$i = strrpos($str,".");
		if (!$i) { return ""; }
		$l = strlen($str) - $i;
		$ext = substr($str,$i+1,$l);
		return $ext;
	}
	
	function insertCarosel($judul,$deskripsi,$id_produk, $gambar)
	{
		$date_created=date('Y-m-d');
		$query=$this->link->prepare("INSERT INTO carosel(judul_caro, deskripsi_caro, id_produk, gambar_carosel, date_created) 
			 VALUES(?,?,?,?,?)");
		$data=array($judul,$deskripsi,$id_produk, $gambar, $date_created);
		$query->execute($data);
		$jml_row=$query->rowCount();
		return $jml_row;
	}
	
}
?>